/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * frmPagoReserva.java
 *
 * Created on 19-feb-2011, 19:51:47
 */

package Presentacion;


import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JOptionPane;

/**
 *
 * @author moises
 */
public class frmPagoReserva extends javax.swing.JFrame {
    Reserva Reserva;
    Double pendiente_act;

    frmReservas frmpadre;
    /** Creates new form frmPagoReserva */
    public frmPagoReserva(){}
    public frmPagoReserva(Reserva r,frmReservas padre) {
        this.setTitle("Pagar Reserva " + r.getCodigoReserva());
        this.Reserva=r;
        this.pendiente_act=Reserva.getImporteRestante();
        initComponents();
        txt_total.setText(Double.toString(Reserva.getImporteTotal()));
        txt_pendiente.setText(Double.toString(pendiente_act));
        txt_pago.addKeyListener(txt_pago_accion);
        frmpadre=padre;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        lbl_importetotal = new javax.swing.JLabel();
        lbl_pago = new javax.swing.JLabel();
        lbl_pago1 = new javax.swing.JLabel();
        lbl_importetotal1 = new javax.swing.JLabel();
        txt_total = new javax.swing.JTextField();
        lbl_importetotal2 = new javax.swing.JLabel();
        txt_pendiente = new javax.swing.JTextField();
        lbl_importetotal3 = new javax.swing.JLabel();
        txt_pago = new javax.swing.JTextField();
        lbl_importetotal4 = new javax.swing.JLabel();
        txt_restante = new javax.swing.JTextField();
        lbl_importetotal5 = new javax.swing.JLabel();
        btn_cancelar = new javax.swing.JButton();
        btn_confirmar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        lbl_importetotal.setText("Importe total del recorrido:");

        lbl_pago.setText("Importe pago cliente:");

        lbl_pago1.setText("Importe restante:");

        lbl_importetotal1.setText("Importe pendiente de pago:");

        txt_total.setEditable(false);
        txt_total.setHorizontalAlignment(javax.swing.JTextField.RIGHT);

        lbl_importetotal2.setText("€");

        txt_pendiente.setEditable(false);
        txt_pendiente.setHorizontalAlignment(javax.swing.JTextField.RIGHT);

        lbl_importetotal3.setText("€");

        txt_pago.setHorizontalAlignment(javax.swing.JTextField.RIGHT);

        lbl_importetotal4.setText("€");

        txt_restante.setEditable(false);
        txt_restante.setHorizontalAlignment(javax.swing.JTextField.RIGHT);

        lbl_importetotal5.setText("€");

        btn_cancelar.setText("Cancelar");
        btn_cancelar.setToolTipText("Cancelar");
        btn_cancelar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btn_cancelar_clic(evt);
            }
        });

        btn_confirmar.setText("Confirmar");
        btn_confirmar.setToolTipText("Confirmar");
        btn_confirmar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btn_confirmar_clic(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lbl_importetotal)
                    .addComponent(lbl_importetotal1)
                    .addComponent(lbl_pago)
                    .addComponent(lbl_pago1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(txt_pendiente, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(lbl_importetotal3, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(txt_total, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(lbl_importetotal2, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                            .addComponent(txt_pago, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(lbl_importetotal4, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(txt_restante, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lbl_importetotal5, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(138, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(242, Short.MAX_VALUE)
                .addComponent(btn_confirmar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btn_cancelar)
                .addGap(24, 24, 24))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbl_importetotal)
                    .addComponent(txt_total, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbl_importetotal2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbl_importetotal1)
                    .addComponent(txt_pendiente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbl_importetotal3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbl_pago)
                    .addComponent(txt_pago, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbl_importetotal4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbl_pago1)
                    .addComponent(txt_restante, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbl_importetotal5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 15, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btn_cancelar)
                    .addComponent(btn_confirmar))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btn_cancelar_clic(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btn_cancelar_clic
        // TODO add your handling code here:
        dispose();
        frmpadre.setEnabled(true);
    }//GEN-LAST:event_btn_cancelar_clic

    private void btn_confirmar_clic(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btn_confirmar_clic
        // TODO add your handling code here:
        try
        {
            Reserva.setImporteRestante(Double.parseDouble(txt_restante.getText()));
            frmpadre.refrescarjlist();
            dispose();
            //frmpadre.setEnabled(true);
        }catch(NumberFormatException nfe){
            JOptionPane.showMessageDialog(null, "El campo Importe pago cliente debe contener un valor numerico");
        }
    }//GEN-LAST:event_btn_confirmar_clic


    KeyListener txt_pago_accion = new KeyListener() {

        public void keyTyped(KeyEvent e) {

        }

        public void keyPressed(KeyEvent e) {
            
        }

        public void keyReleased(KeyEvent e) {
            try{
            pendiente_act=Double.parseDouble(txt_pendiente.getText())-Double.parseDouble(txt_pago.getText());
            txt_restante.setText(Double.toString(pendiente_act));
            }catch(Exception ex){
            txt_restante.setText("Error");
            }
        }
    };

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btn_cancelar;
    private javax.swing.JButton btn_confirmar;
    private javax.swing.JLabel lbl_importetotal;
    private javax.swing.JLabel lbl_importetotal1;
    private javax.swing.JLabel lbl_importetotal2;
    private javax.swing.JLabel lbl_importetotal3;
    private javax.swing.JLabel lbl_importetotal4;
    private javax.swing.JLabel lbl_importetotal5;
    private javax.swing.JLabel lbl_pago;
    private javax.swing.JLabel lbl_pago1;
    private javax.swing.JTextField txt_pago;
    private javax.swing.JTextField txt_pendiente;
    private javax.swing.JTextField txt_restante;
    private javax.swing.JTextField txt_total;
    // End of variables declaration//GEN-END:variables

/**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                double total=1200;
                double pendiente=800;
                new frmPagoReserva().setVisible(true);
            }
        });
    }

}
    
